<template>
	<div class="container">
		<div class="jx-container">
      <div class="select-type">
        <div class="item table-item">
          <div class="right">
            <div class="item-inline">
              <span>订单开始时间</span>
              <el-date-picker
                class="tel-value"
                v-model="params_list.start"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="选择订单开始时间"
                align="right">
              </el-date-picker>
            </div>
            <div class="item-inline">
              <span>订单结束时间</span>
              <el-date-picker
                class="tel-value"
                v-model="params_list.end"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="选择订单结束时间"
                align="right">
              </el-date-picker>
            </div>
            <div class="item-inline">
              <span>用户昵称</span>
              <el-input class="tel-value" v-model="params_list.username" placeholder="请输入用户昵称"></el-input>
            </div>
            <div class="item-inline">
              <span>姓名</span>
              <el-input class="tel-value" v-model="params_list.name" placeholder="请输入姓名"></el-input>
            </div>
            <div class="item-inline">
              <span>手机号</span>
              <el-input class="tel-value" v-model="params_list.tel" placeholder="请输入手机号"></el-input>
            </div>
            <div class="item-inline">
              <span>是否实名</span>
              <el-select class="tel-value" v-model="params_list.isReal" placeholder="请选择">
                <el-option label="是" value="true"></el-option>
                <el-option label="否" value="false"></el-option>
              </el-select>
            </div>
            <div class="item-inline">
              <span>所在地区</span>
              <el-cascader
                class="tel-value"
                v-model="params_list.address"
                :options="options"
                :props="props"
                @change="handleChange">
              </el-cascader>
            </div>
            <div class="item-inline">
              <span>注册时间</span>
              <el-date-picker
                class="tel-value"
                v-model="params_list.time"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="选择注册时间"
                align="right">
              </el-date-picker>
            </div>
            <div class="item-inline">
              <el-button class="jx-btn" type="primary" @click="search">搜索</el-button>
            </div>
          </div>
        </div>
      </div>
      <div class="jx-table">
        <div class="title">
          <img class="icon" src="/static/img/icon-platform.png"/>
          用户列表
          <div class="add-new">
            <el-button class="jx-btn" type="primary" :loading="boo.isExport" @click="exportRow">{{boo.isExport ? '请稍后……' : '导出'}}</el-button>
          </div>
        </div>
        <el-table :data="list" border style="width: 100%" v-loading="boo.loading">
          <el-table-column type="index" label="序列" width="60" align="center">
            <template slot-scope="scope">
              <span>{{(scope.$index + 1) + ((params_list.page - 1) * params_list.size)}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="consumerNickname" label="用户昵称" width="150" align="center" :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <span v-if="scope.row.consumerStatus == '正常'">{{scope.row.consumerNickname}}</span>
              <span v-else>{{scope.row.consumerNickname}}<img class="icon" src="/static/img/u780.png"/></span>
            </template>
          </el-table-column>
          <el-table-column prop="consumerNo" label="用户ID" width="120" align="center" :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <el-button @click="viewRow(scope.row)" type="text" size="small">{{scope.row.consumerNo}}</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="createAt" label="注册时间" width="150" align="center" :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column prop="consumerLocationProvinceCity" label="所在地区" align="center">
          </el-table-column>
          <el-table-column prop="isRealname" label="是否实名" align="center" >
            <template slot-scope="scope">
              {{scope.row.isRealname ? '是' : '否'}}
            </template>
          </el-table-column>
          <el-table-column prop="isRealname" label="是否开通会员" align="center" >
            <template slot-scope="scope">
              {{scope.row.isReal ? '是' : '否'}}
            </template>
          </el-table-column>
          <el-table-column prop="carCount" label="绑定车辆数" align="center">
          </el-table-column>
          <el-table-column prop="consumerSource" label="用户来源" align="center" :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column label="操作" width="120" align="center">
            <template slot-scope="scope">
              <el-button @click="hiddenRow(scope.row)" type="text" size="small">{{scope.row.consumerStatus == '正常' ? '冻结' : '解冻'}}</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div v-if="list.length != 0" class="jx-pagination">
          <el-pagination @current-change="pageChange" @size-change="handleSizeChange" :current-page="params_list.page" :page-sizes="[10,50,100]" :page-size="params_list.size" layout="total, sizes, prev, pager, next, jumper"
            :total="other.allRow">
          </el-pagination>
        </div>
      </div>
    </div>
	</div>
</template>

<script>
	export default {
		data() {
			return {
        https: {
          list: this.$api.user,
          common: this.$api.common,
        },
        boo: {
          loading: false,
          isExport: false,
        },
        other: {
          allRow: 1,
        },
        list: '',
        params_list: {
          page: 1,
          size: 10,
          start: '',
          end: '',
          name: '',
          username: '',
          tel: '',
          isReal: '',
          address: '',
          time: '',
        },
        props: {
          expandTrigger: 'click', 
          value: 'field',
          label: 'field',
        },
        options: '',
			}
		},
		mounted(){
      let _self = this
      _self.getList()
      _self.getAddress()
    },
		methods: {
      getList(){
        let _self = this
        let params = {
          pageNumber: _self.params_list.page,
          pageSize: _self.params_list.size,
          orderAtBegin: _self.params_list.start || [],
          orderAtEnd: _self.params_list.end || [],
          consumerNickname: _self.params_list.username,
          consumerRealname: _self.params_list.name,
          consumerPhone: _self.params_list.tel,
          isRealname: _self.params_list.isReal,
          consumerLocationProvinceCity: _self.params_list.address,
          createAt: _self.params_list.time || [],
          orderBy: '',
        }
        _self.boo.loading = true
        let success = (res)=>{
          res = res.data
          if(res.retCode == 1){
            _self.list = res.retObject.list
            _self.other.allRow = Number(res.retObject.totalRow)
          }else{
            _self.$message.error(res.retMsg)
          }
          _self.boo.loading = false
        }
        _self.$axios.get(_self.https.list.list, params, success) 
      },
      getAddress(){
        let _self = this
        let success = (res)=>{
          res = res.data
          if(res.retCode == 1){
            _self.options = res.retObject
          }else{
            _self.$message.error(res.retMsg)
          }
        }
        _self.$axios.get(_self.https.common.address, {}, success) 
      },
      pageChange(val){
        let _self = this
        _self.params_list.page = val
        _self.getList()
      },
      handleSizeChange(val) {
        let _self = this
        _self.params_list.size = val
        _self.getList()
      },
      search(){
        let _self = this
        _self.getList()
      },
      exportRow(){

      },
      hiddenRow(){
        
      },
      viewRow(item){
        let _self = this
        let params = {
          path: '/user/detail/user_detail?id=',
          query: item.consumerId
        }
        _self.$router.push(params.path + params.query)
      }
    }
	}

</script>
<style scoped lang="sass">
  .jx-table
    .el-table 
      .cell
        .icon
          width: 16px
          height: 17px
          position: relative
          top: 4px
          margin-left: 5px
  .select-type .table-item .right span
    width: 95px
</style>
